#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Sprite3D < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_default_variables
    img = M3G::Image2D.new    M3G::Image2D::RGBA, 64, 64
    app = M3G::Appearance.new 
    spr = M3G::Sprite3D.new   true, img, app

    assert_equal 0 , spr.crop.x
    assert_equal 0 , spr.crop.y
    assert_equal 64, spr.crop.width
    assert_equal 64, spr.crop.height

    assert_equal true, spr.scaled?
    assert_equal img , spr.image
    assert_equal app , spr.appearance
  end

  def test_set_variables
    img = M3G::Image2D.new  M3G::Image2D::RGBA, 64, 64
    app = M3G::Appearance.new
    spr = M3G::Sprite3D.new false, img, app

    spr.crop = [1,2,30,40]

    assert_equal 1 , spr.crop.x
    assert_equal 2 , spr.crop.y
    assert_equal 30, spr.crop.width
    assert_equal 40, spr.crop.height

    app2 = M3G::Appearance.new
    img2 = M3G::Image2D.new  M3G::Image2D::RGBA, 128, 128
    spr.image      = img2
    spr.appearance = app2

    assert_equal 0  , spr.crop.x
    assert_equal 0  , spr.crop.y
    assert_equal 128, spr.crop.width
    assert_equal 128, spr.crop.height

    assert_equal false, spr.scaled?
    assert_equal img2  , spr.image
    assert_equal app2  , spr.appearance
  end

  def test_duplicte
    img  = M3G::Image2D.new  M3G::Image2D::RGBA, 64, 64
    app  = M3G::Appearance.new
    spr1 = M3G::Sprite3D.new false, img, app
    spr1.crop = [1,2,30,40]

    spr2 = spr1.duplicate

    assert_equal 1    , spr1.crop.x
    assert_equal 2    , spr1.crop.y
    assert_equal 30   , spr1.crop.width
    assert_equal 40   , spr1.crop.height
    assert_equal false, spr1.scaled?
    assert_equal img  , spr1.image
    assert_equal app  , spr1.appearance
  end

  def test_references
    img = M3G::Image2D.new    M3G::Image2D::RGBA, 64, 64
    app = M3G::Appearance.new
    spr = M3G::Sprite3D.new   true, img, app
  
    objs = spr.references
    
    assert_equal 2, objs.length
    assert_equal img, objs[0]
    assert_equal app, objs[1]
  end

end
